package weaver.interfaces.jjy.duss.hr;

import com.sap.mw.jco.JCO;
import weaver.interfaces.jjy.duss.util.SAPConnPool;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @program: ecology-9-demo
 * @description: 月度绩效A
 * @author: Dusongsong
 * @create: 2019-12-07
 */

public class ZFM_HR_031A {
    public Map execute(Map<String, String> map ,List<Map<String, String>> mapList) {

        SAPConnPool SAPConn = new SAPConnPool();
        JCO.Client myConnection = SAPConn.getConnection();
        JCO.Function bapi = SAPConn.excuteBapi("ZFM_HR_031A");
        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();//输入表的处理

        //入参为表
        JCO.Table t1 = inputtable.getTable("IT_HEAD");
            t1.appendRow();
            t1.setValue(map.get("NUMID"), "NUMID");         //唯一标识
            t1.setValue(map.get("GJAHR"), "GJAHR");         //年度
            t1.setValue(map.get("MONAT"), "MONAT");         //月度
            t1.setValue(map.get("BMBM"), "BMBM");           //部门编码
            t1.setValue(map.get("BMBM_T"), "BMBM_T");       //部门编码名称
            t1.setValue(map.get("BMGDJBXY"), "BMGDJBXY");         //部门规定加班效益工资
            t1.setValue(map.get("BMGDJBTC"), "BMGDJBTC");         //部门规定加班提成工资
            t1.setValue(map.get("BMGDSK"), "BMGDSK");         //部门规定收款提成
            t1.setValue(map.get("BMGDZZSKJ"), "BMGDZZSKJ");         //部门规定自助收款机提成
            t1.setValue(map.get("BMGDJL"), "BMGDJL");         //部门规定激励奖金
            t1.setValue(map.get("BMSBJBXY"), "BMSBJBXY");         //部门上报加班效益工资
            t1.setValue(map.get("BMSBJBTC"), "BMSBJBTC");         //部门上报加班提成工资
            t1.setValue(map.get("BMSBSK"), "BMSBSK");         //部门上报收款提成
            t1.setValue(map.get("BMSBZZSKJ"), "BMSBZZSKJ");         //部门上报自助收款机提成
            t1.setValue(map.get("BMSBJL"), "BMSBJL");         //部门上报激励奖金*/
            JCO.Table t2 = inputtable.getTable("IT_ITEM");
        Iterator<Map<String, String>> iter = mapList.iterator();
           while (iter.hasNext()){
            Map<String,String>  map1 = iter.next();
            t2.appendRow();
            t2.setValue(map1.get("NUMID"), "NUMID");         //主表标识
            t2.setValue(map1.get("GZ"), "GZ");         //柜组编码
            t2.setValue(map1.get("GZ_T"), "GZ_T");         //柜组名称
            t2.setValue(map1.get("XYJE"), "XYJE");         //效益金额
        }

        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        JCO.Table stu = Table00.getTable("IT_HEAD");
        Map<String, String> mapreturn = new HashMap<>();
        String flag = (String) stu.getValue("ZFLAG");
        String message = (String) stu.getValue("ZMESG");
        mapreturn.put("flag", flag);
        mapreturn.put("message", message);
        System.out.println("返回结果：" + mapreturn);
        JCO.releaseClient(myConnection);
        return mapreturn;
    }

}
